package com.zyy.joseata.config;

import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;

/**
 * @author zhangyy
 */
@Data
@ConfigurationProperties("joseata.service")
public class SeataConfigProperties {

    /** seata服务地址: ip:port */
    private String seataServer;

    /** 事务类型: mq, tcc */
    private String seataType;

    @Value("${spring.application.name}")
    private String serviceName;

    public String getSeataServerIp(){
        String serverIp = "localhost";
        if(seataServer != null && seataServer != ""){
            int colonIndex = seataServer.indexOf(":");
            serverIp = seataServer.substring(0,colonIndex);
        }
        return serverIp;
    }

    public int getSeataServerPort(){
        int port = 9188;
        if(seataServer != null && seataServer != "") {
            int colonIndex = seataServer.indexOf(":");
            port = Integer.parseInt(seataServer.substring(colonIndex + 1));
        }
        return port;
    }

}
